//  Created by 邓盛明 on 2022/2/16.
//  Copyright © 2022 Talkfun. All rights reserved.
//

import UIKit


class TFBitmapView: UIView {
    var bitView:UIView!
    var tipsView:UIView!
    //占位图
    var bitmapImg:UIImageView!
    //已下课
    var liveLab:UILabel!
    var tipsLab:UILabel!
    var yuyinView:UIView!
    var adminImg:UIImageView!//老师头像

    override init(frame: CGRect) {
        super.init(frame: frame)
        self.bitmapImg = UIImageView.init()
        self.bitmapImg.image = UIImage.init(named: "HTLive.bundle/nostart")
        addSubview(self.bitmapImg)
        
        self.tipsView = UIView.init()
    
        self.tipsView.backgroundColor = UIColor.clear
        addSubview(self.tipsView)
        
        self.liveLab = UILabel.init()
        self.liveLab.font = UIFont.PingFang(size: 12)
        self.liveLab.text = "老师已下课";
        self.liveLab.isHidden = true
        self.liveLab.textColor = UIColor.white
        self.liveLab.textAlignment = .center
        self.tipsView.addSubview(self.liveLab)

        
        self.tipsLab = UILabel.init()
        self.tipsLab.font = UIFont.PingFang(size: 16)
        self.tipsLab.text = "如是不正常下课，请等待老师重连";
        self.tipsLab.textColor = UIColor.white
        self.tipsLab.isHidden = true
        self.tipsLab.textAlignment = .center
        self.tipsView.addSubview(self.tipsLab)
        
        
        self.yuyinView = UIView.init()
        self.yuyinView.isHidden = true
        self.yuyinView.layer.masksToBounds = true
        self.yuyinView.layer.cornerRadius = 47;
        self.yuyinView.backgroundColor = UIColor(red: 255/255.0, green: 255/255.0, blue: 255/255.0, alpha: 0.2)
        addSubview(self.yuyinView)
  
        self.adminImg = UIImageView.init()
        self.adminImg.layer.masksToBounds = true
        self.adminImg.layer.cornerRadius = 40;
        self.yuyinView.addSubview(self.adminImg)
        
    }

    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        //背影
        self.bitmapImg.frame = CGRect(x: (self.bounds.size.width-200)/2.0, y: (self.bounds.size.height-200-(28-6)-(28-2))/2.0, width: 200, height: 200)
        
        self.tipsView.frame = CGRect(x: 0, y: 0, width: self.frame.size.width, height: self.frame.size.height)
       
       self.tipsLab.frame = CGRect(x: 0, y: self.bitmapImg.frame.maxY-28-6, width: self.frame.size.width, height: 28)
   
       self.liveLab.frame = CGRect(x: (self.frame.size.width-200)/2.0, y: self.tipsLab.frame.maxY+2, width: 200, height: 28)
        
      
        
         self.yuyinView.frame = CGRect(x: (self.bounds.size.width-94)/2.0, y: (self.bounds.size.height-94)/2.0, width: 94, height: 94)
         self.adminImg.frame = CGRect(x: 7, y: 7, width: 80, height: 80)
    }
    
  @objc public func updateLiveStatus1(_ model:TFBitmapModel){
      self.liveLab.isHidden = false
        if (model.isNOWork) {  //无网络
           
            self.tipsLab.text = "网络异常,请检查网络";
            self.tipsLab.isHidden = false
            
            self.yuyinView.isHidden = true;
            self.tipsView.isHidden = false
            self.liveLab.isHidden = true
            self.bitmapImg.image = UIImage.init(named: "HTLive.bundle/neterror")

        } else {
           
            if (model.status == TalkfunLiveStatusWait) { //未开始
                
                self.bitmapImg.image = UIImage.init(named: "HTLive.bundle/nostart")
                
                self.liveLab.isHidden = true;
                self.liveLab.text = "直播未开始";
                self.yuyinView.isHidden = true;
                self.tipsView.isHidden = false;
                self.tipsLab.isHidden = false
                let strtime:NSString = TalkfunSharedTools.getTimestamp(mStr: model.startTime as NSString)
         
                let str = "预定直播时间 " + "\(strtime)"
                let attr: [NSAttributedString.Key : Any] = [.font: UIFont.systemFont(ofSize: 18),.foregroundColor: UIColor.white, ]
                let string = NSMutableAttributedString.init(string: str, attributes: attr)
                let attr1: [NSAttributedString.Key : Any] = [.font: UIFont.systemFont(ofSize: 19),.foregroundColor: UIColor(red: 65/255.0, green: 150/255.0, blue: 235/255.0, alpha: 1.0), ]
                string.addAttributes(attr1, range: NSMakeRange(7, strtime.length))
       
             
                if (model.isTimeStart) {
                    self.liveLab.isHidden = false;
                    self.tipsLab.attributedText = string;
                } else {
                    self.liveLab.isHidden = true;
                    self.tipsLab.text = "直播未开始";
                }
               
               
            } else if (model.status == TalkfunLiveStatusStart) {  //开始
                

                self.tipsView.isHidden = true
                //老师头像

   
            } else if (model.status == TalkfunLiveStatusStop) {  //结束

                self.bitmapImg.image = UIImage.init(named: "HTLive.bundle/over")
                self.tipsLab.text = "老师已下课";
                self.liveLab.isHidden = false
                self.liveLab.text = "如是不正常下课，请等待老师重连";
                self.tipsLab.isHidden = false
                self.yuyinView.isHidden = true
                self.tipsView.isHidden = false;
            }
        }
        

    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
